﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IntraVision.Web;
using Model;

public class ScheduleDayExceptionController : EntityListController<ScheduleDayException,NotarialServiceDataContext>
{
    public ScheduleDayExceptionController()
    {
        ViewData["whitebg"] = true;
        LayoutPath = "~/views/layouts/popup.haml";
    }

    protected override void EntityLoaded(NotarialServiceDataContext dc, ScheduleDayException entity)
    {
        if (entity.Id == 0)
        {
            entity.ScheduleId = Int32.Parse(Request["scheduleid"]);
            entity.Schedule = dc.Schedules.SingleOrDefault(s => s.Id == entity.ScheduleId);
            entity.Date = DateTime.Parse(Request["date"]);

            var wh = entity.Schedule.GetWorkingHours(entity.Date);
            if (wh != null && wh.TimeStart.HasValue)
            {
                entity.TimeStart = wh.TimeStart;
                entity.TimeEnd = wh.TimeEnd;
            }
            if (wh != null && wh.BreakStart.HasValue)
            {
                entity.BreakStart = wh.BreakStart;
                entity.BreakEnd = wh.BreakEnd;
            }
        }
    }
}
